<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-L-admin1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script src="../js/checkbox.js"></script>
    <script src="../js/queryByName.js"></script>
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">导航</a>
        <a>
          <cite>预约信息</cite></a>
      </span>
    <a class="layui-btn layui-btn-primary layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:38px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <div class="layui-form layui-col-md12 x-so">
            <!--            <div class="layui-input-inline">-->
            <!--                <select name="contrller">-->
            <!--                    <option value="">订单状态</option>-->
            <!--                    <option value="0">待确认</option>-->
            <!--                    <option value="1">已确认</option>-->
            <!--                    <option value="2">已取消</option>-->
            <!--                    <option value="3">已完成</option>-->
            <!--                </select>-->
            <!--            </div>-->
            <input type="text" id="orderId" placeholder="请输入订单号" autocomplete="off" class="layui-input">
            <button onclick="queryByOrderId()" class="layui-btn"><i class="layui-icon">&#xe615;</i></button>
            <input type="text" id="labname" placeholder="请输入实验室名称" autocomplete="off" class="layui-input">
            <button onclick="queryByLabName()" class="layui-btn"><i class="layui-icon">&#xe615;</i></button>
        </div>
    </div>
    <xblock>
        <button class="layui-btn layui-btn-danger" onclick="record_delSome()"><i class="layui-icon"></i>批量删除</button>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>
                <label>
                    <input type="checkbox" onclick="checkAll(this)"/>
                </label>
            </th>
            <th>订单编号</th>
            <th>实验室ID</th>
            <th>实验室名称</th>
            <th>用户ID</th>
            <th>用户姓名</th>
            <th>所在院系</th>
            <th>预约日期</th>
            <th>订单状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id="record">
        </tbody>
    </table>
    <!--      <div class="page">-->
    <!--        <div>-->
    <!--          <a class="prev" href="">&lt;&lt;</a>-->
    <!--          <a class="num" href="">1</a>-->
    <!--          <span class="current">2</span>-->
    <!--          <a class="num" href="">3</a>-->
    <!--          <a class="num" href="">489</a>-->
    <!--          <a class="next" href="">&gt;&gt;</a>-->
    <!--        </div>-->
    <!--      </div>-->
</div>
<script>
    //判断登陆状态
    $(function () {
        $.ajax({
            type: "post",
            url: "http://localhost:8080/user/getCurrentUser",
            success: function (result) {
                if (result.code == '200' && result.object.priority == '2') {
                    findAllRecord();
                } else {
                    alert("请先登录账号！");
                    window.location.href = "login.html";
                }
            }
        });
    });

    //局部刷新全部预约信息
    function findAllRecord() {
        $.post('http://localhost:8080/record/findAllRecord', function (result) {
            let res = result.object;
            let str = "";
            for (let i = 0; i < res.length; i++) {
                str += "<tr><td>\n" +
                    "<input type='checkbox' name='checkbox' value='"+res[i].recordid+"'/>\n" +
                    "</td>";
                str += "<td>" + res[i].recordid + "</td>";
                str += "<td>" + res[i].labid + "</td>";
                str += "<td>" + res[i].labname + "</td>";
                str += "<td>" + res[i].userid + "</td>";
                str += "<td>" + res[i].username + "</td>";
                str += "<td>" + res[i].faculty + "</td>";
                str += "<td>" + res[i].bookTime + "</td>";
                str += "<td>" + res[i].state + "</td>";
                str += "<td class=\"td-manage\">\n" +
                    // "<a title='编辑' onclick=\"user_edit_show('编辑','order-edit.html'," + res[i].recordid + ")\" href='javascript:;'>\n" +
                    // "<i class=\"layui-icon\">&#xe642;</i>\n" +
                    // "</a>\n" +
                    "<a title='删除' onclick='record_del(this," + res[i].recordid + ")' href='javascript:;'>\n" +
                    "<i class=\"layui-icon\">&#xe640;</i>\n" +
                    "</a>\n" +
                    "</td></tr>";
            }
            $("#record").html(str);
        });
    }

    //根据订单id局部刷新预约信息
    function queryByOrderId() {
        let data = {"recordid": $("#orderId").val()};
        $.post('http://localhost:8080/record/findRecordById', data, function (result) {
            let res = result.object;
            let str = "";
            str += "<tr><td>\n" +
                "<input type='checkbox' name='checkbox' value='"+res.recordid+"'/>\n" +
                "</td>";
            str += "<td>" + res.recordid + "</td>";
            str += "<td>" + res.labid + "</td>";
            str += "<td>" + res.labname + "</td>";
            str += "<td>" + res.userid + "</td>";
            str += "<td>" + res.username + "</td>";
            str += "<td>" + res.faculty + "</td>";
            str += "<td>" + res.bookTime + "</td>";
            str += "<td>" + res.state + "</td>";
            str += "<td class=\"td-manage\">\n" +
                // "<a title='编辑' onclick=\"user_edit_show('编辑','order-edit.html'," + res.recordid + ")\" href='javascript:;'>\n" +
                // "<i class=\"layui-icon\">&#xe642;</i>\n" +
                // "</a>\n" +
                "<a title='删除' onclick='record_del(this," + res.recordid + ")' href='javascript:;'>\n" +
                "<i class=\"layui-icon\">&#xe640;</i>\n" +
                "</a>\n" +
                "</td></tr>";
            $("#record").html(str);
        });
    }

    /*删除*/
    function record_del(obj, recordid) {
        layer.confirm('确认要删除吗？', function (index) {
            //发异步删除数据
            $.ajax({
                type: "delete",
                url: "http://localhost:8080/record/deleteRecordById",
                data: "recordid=" + recordid,
                success: function (result) {
                    if (result.code == '200') {
                        //obj是属于js对象
                        //js对象转换成jquery对象
                        let tr = $(obj).parent().parent();
                        tr.remove();
                        // $(obj).parents("tr").remove();
                        layer.msg('已删除!', {icon: 1, time: 1000});
                    }
                }
            });
        });
    }

    //删除多个订单
    function record_delSome() {
        let checkboxes = document.getElementsByName("checkbox");
        let check_val = [];
        for (let k in checkboxes) {
            if (checkboxes[k].checked)
                check_val.push(checkboxes[k].value);
        }
        $.ajax({
            type: "delete",
            url: "http://localhost:8080/record/deleteRecordSome",
            data: "ids=" + check_val,
            success: function (result) {
                if (result.code == '200') {
                    //obj是属于js对象
                    //js对象转换成jquery对象
                    let trs = [];
                    for (let s = 0; s < checkboxes.length; s++) {
                        if (checkboxes[s].checked) {
                            let tr = checkboxes[s];
                            trs.push(tr);
                        }
                    }
                    for (let i = 0; i < trs.length; i++) {
                        let tr = $(trs[i]).parent().parent();
                        tr.remove();
                    }
                }
            }
        });
    }
</script>
</body>

</html>